package com.prig.base.service;

import com.prig.base.entity.RolePermissionRelation;
import com.prig.base.entity.RolePermissionRelationId;
import com.prig.base.repository.RolePermissionRelationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RolePermissionService {
    private RolePermissionRelationRepository rolePermissionRelationRepository;
    @Autowired
    public void setRolePermissionRelationRepository(RolePermissionRelationRepository rolePermissionRelationRepository) {
        this.rolePermissionRelationRepository = rolePermissionRelationRepository;
    }
    public RolePermissionRelation add(RolePermissionRelationId id){
        RolePermissionRelation rolePermissionRelation = new RolePermissionRelation(id);
        return rolePermissionRelationRepository.save(rolePermissionRelation);
    }
    public void delete(RolePermissionRelationId id){
        RolePermissionRelation rolePermissionRelation = new RolePermissionRelation(id);
        rolePermissionRelationRepository.delete(rolePermissionRelation);
    }

    public List<RolePermissionRelationId> getRolePermissionRelationId(long roleId) {
        return rolePermissionRelationRepository.findByRoldId(roleId);
    }

    public void delete(long roleId) {
        rolePermissionRelationRepository.delete(roleId);
    }

    public void add(List<RolePermissionRelationId> list) {
        list.forEach(e->add(e));
    }
}
